# coding:utf-8
import pymysql

import pandas as pd
import csv
import re
import numpy as np
from datetime import datetime

# 打开数据库连接
db = pymysql.connect(host="localhost", user="root", password="hui123456", db='dbtest')
# 使用cursor()方法创建一个游标对象cursor
cursor = db.cursor()


sql="""
     SELECT shop, day(day) as "日期" ,Product_BianMa as "商家编码", SUM(Product_num) as "商品数量" from doudian_day 
     WHERE MONTH(day)=10  AND ( order_zt="已签收"  OR order_zt="待发货"  OR order_zt="已完成"  OR order_zt="已发货"  OR order_zt="已支付")
     AND order_sh != "退款成功"  AND order_sh != "售后完成"  AND order_sh != "退款完成"  AND order_sh != "已全额退款" group by shop, day(day),Product_BianMa
    """

sql1="""
     select shop, day(day) as "日期" ,Product_BianMa as "商家编码", SUM(Product_num) as "商品数量"   from niandu_day 
     WHERE MONTH(day)=10  and (order_zt="完成" OR order_zt="等待出库" OR order_zt="等待确认收货" OR order_zt="已签收" OR order_zt="待配货"  OR order_zt="待发货" OR order_zt="交易成功" OR order_zt="已完成" OR order_zt="卖家已发货，等待买家确认"  OR order_zt="买家已付款，等待卖家发货" OR order_zt="已发货" OR order_zt="调度中" 
      OR order_zt="已收货" OR order_zt="已发货未签收" OR order_zt="已发货，待签收" OR order_zt="(锁定)等待确认收货" OR order_zt="已发货，待收货" OR order_zt="(锁定)等待确认收货" OR order_zt="部分发货" OR order_zt="买家已付款,等待卖家发货" OR order_zt="卖家已发货" OR order_zt="买家已付款" OR order_zt="发货即将超时" OR order_zt="卖家部分发货"OR order_zt="待买家收货"OR order_zt="待卖家发货"OR order_zt="部分发货中")
     AND order_sh != "退款成功"  AND order_sh != "售后完成"  AND order_sh != "退款完成"  AND order_sh != "退货退款完成 " group by shop, day(day),Product_BianMa
     """


cursor.execute(sql)
result = cursor.fetchall()
cursor.execute(sql1)
result1 = cursor.fetchall()
xs1 = pd.DataFrame(list(result), columns=['平台', '日期', '商家编码', '商品数量'])
xs11 = pd.DataFrame(list(result1), columns=['平台', '日期', '商家编码', '商品数量'])
xs = pd.concat([xs1, xs11])
xs['平台1'] = '线上'
xs['商品数量'] = xs['商品数量'].map(lambda x: int(x))

date_concat_dl = xs.groupby([xs['平台'], xs['日期'], xs['商家编码']], as_index=False).agg(商品数量=('商品数量', 'sum'))
# douchao = pd.read_excel(r'G:\工作\2025年订单\10月\抖超.xlsx')

maochao = pd.read_excel(r'G:\工作\2025年订单\10月\猫超.xlsx')
ziying1 = pd.read_excel(r'G:\工作\2025年订单\10月\自营1.xlsx')
ziying2 = pd.read_excel(r'G:\工作\2025年订单\10月\自营2.xlsx')

ziying2_dl = pd.read_excel(r'G:\工作\2025年订单\10月\自营2.xlsx')

pp1 = pd.read_excel(r'G:\工作\猫超+自营SKU编码.xlsx', dtype={'SKU': str})
# print(pp)
# douchao['退款成功金额'] = 0
# douchao['平台'] = '抖音超市'
# douchao['月'] = douchao['日期'].map(lambda x: str(x)[0:8])  # 调整
# douchao_date = douchao.loc[
#     :, ['月', '货品ID', '支付货品件数', '支付GMV', '退款成功金额', '支付货品件数', '平台', '货品名']]  # 无退款
# douchao_date.columns = ['日期', 'SKU', '销售单量', '销售额', '退款金额', '成交商品件数', '平台', '产品名称']

maochao['商品数量'] = maochao['支付商品件数'] - maochao['退款成功商品件数']
maochao['平台'] = '猫超'
maochao['月'] = maochao['统计日期'].map(lambda x: f"{str(x)[0:4]}-{str(x)[4:6]}-{str(x)[6:8]}" if len(str(x)) >= 8 else str(x)[0:8])
maochao_date = maochao.loc[
    :, ['月', '商品ID', '支付子订单数(剔退款)', '支付金额(剔退款)', '退款成功金额', '商品数量', '平台']]
maochao_date.columns = ['日期', 'SKU', '销售单量', '销售额', '退款金额', '成交商品件数', '平台']

ziying1['退款成功金额'] = 0
ziying1['平台'] = '京东自营1'
ziying1_date = ziying1.loc[:, ['时间', 'SKU', '成交单量', '成交金额', '退款成功金额', '成交商品件数', '平台']]

ziying1_date.columns = ['日期', 'SKU', '销售单量', '销售额', '退款金额', '成交商品件数', '平台']

ziying2 = ziying2[
    (ziying2['SKU'] != 100095090135) & (ziying2['SKU'] != 100111765304) & (ziying2['SKU'] != 100111765306) & (
                ziying2['SKU'] != 100122053209)]
ziying2['退款成功金额'] = 0
ziying2['平台'] = '京东自营2'
ziying2_date = ziying2.loc[:, ['时间', 'SKU', '成交单量', '成交金额', '退款成功金额', '成交商品件数', '平台']]

ziying2_date.columns = ['日期', 'SKU', '销售单量', '销售额', '退款金额', '成交商品件数', '平台']

ziying2_dl['退款成功金额'] = 0
ziying2_dl['平台'] = '京东自营2'
ziying2dl_date = ziying2_dl.loc[:, ['时间', 'SKU', '成交单量', '成交金额', '退款成功金额', '成交商品件数', '平台']]
ziying2dl_date.columns = ['日期', 'SKU', '销售单量', '销售额', '退款金额', '成交商品件数', '平台']

res = pd.concat([maochao_date, ziying1_date, ziying2_date])
# ['商家编码']去空格
res['SKU'] = res['SKU'].astype(str).str.strip()
res_m = pd.merge(res, pp1, on=['SKU'], how='left')

# result = pd.concat([res_m, douchao_date])
result = res_m
result_mc = result[['销售额', '销售单量', '退款金额']].groupby([result['日期'], result['平台']]).sum()
result_mc.to_excel(r'G:\工作\2025年订单\10月\结果\猫超等销售额汇总10月.xlsx')

res_dl = pd.concat([maochao_date, ziying1_date, ziying2dl_date])
# ['商家编码']去空格
res_dl['SKU'] = res_dl['SKU'].astype(str).str.strip()
res_mdl = pd.merge(res_dl, pp1, on=['SKU'], how='left')

# result_dl = pd.concat([res_mdl, douchao_date])
result_dl=res_mdl

mc = result_dl
pp = pd.read_excel(r'G:\工作\商家编码匹配产品.xlsx')  # 匹配表
pp_zh = pd.read_excel(r'G:\工作\商家编码匹配产品.xlsx', sheet_name='组合装')  # 匹配表
mc = mc[mc['成交商品件数'] > 0]
mc_date = mc.loc[:, ['日期', '产品名称', '成交商品件数', '平台']]
mc_date.columns = ['日期', '商家编码', '商品数量', '平台1']
mc_date['平台'] = '其他'

xs = date_concat_dl
xs_date = xs.loc[:, ['日期', '商家编码', '商品数量', '平台']]
xs_date['平台1'] = '线上'
result = pd.concat([xs_date, mc_date])
result_1 = pd.concat([xs_date, mc_date])  # 用于提取组合装

# ['商家编码']去空格
result['商家编码'] = result['商家编码'].str.strip()
# 去空值
result.dropna(subset=['商家编码'], inplace=True)
# 去掉抖音直播间赠品，电煮锅，空值
result = result[(result['商家编码'] != 'logo定制电煮锅1个') &
                (result['商家编码'] != '抖音直播间赠品') &
                (result['商家编码'] != '红色电煮锅甄嬛传版1个') &
                (result['商家编码'] != '') &
                (result['商家编码'] != '红色电煮锅') &
                (result['商家编码'] != '搪瓷碗1个')


]

# 所有产品，包含组合装
# 处理每行多订单情况
# 分列
s_1 = []  # 分列后以列表形式保存
r_1 = []  # 添加每个分列后的产品
r_3 = []  # 添加商品数量
r_4 = []  # 添加平台
r_5 = []  # 添加平台1 线上
r_6 = []  # 添加月
for date_s in list(result['商家编码']):
    if '+' in date_s:
        date_split = str(date_s).split('+')
        s_1.append(date_split)

    elif '，' in date_s:
        date_split = str(date_s).split('，')
        if '赠' in date_split[0]:
            date_split_1 = date_split[0].split('赠')
            s_1.append(date_split_1)
        else:
            s_1.append([date_split[0]])


    elif '赠' in date_s:

        date_split = str(date_s).split('赠')
        s_1.append(date_split)


    elif '＋' in date_s:
        date_split = str(date_s).split('＋')
        s_1.append(date_split)
    else:
        s_1.append([date_s])

result['编码分裂'] = s_1

# date_concat.reindex(range(len(date_concat['编码分裂'])))
date_concat_s = result.reset_index(drop=True)

# print(date_concat_s)
# cc=date_concat_s['编码分裂']

n = 0
for i in list(date_concat_s['编码分裂']):

    # 查i对应的索引值
    # n=list(date_concat['编码分裂']).index(i)
    # 分裂后生成的是列表，所以用列表长度判定
    if len(i) == 1:  # 判定是否有多的订单
        r_1.append(i[0])
        r_3.append(list(date_concat_s['商品数量'])[n])
        r_4.append(list(date_concat_s['平台'])[n])
        r_5.append(list(date_concat_s['平台1'])[n])
        r_6.append(list(date_concat_s['日期'])[n])

    else:  # 多订单的情况下分行并对应单量
        for c in i:
            r_1.append(c)
            r_3.append(list(date_concat_s['商品数量'])[n])
            r_4.append(list(date_concat_s['平台'])[n])
            r_5.append(list(date_concat_s['平台1'])[n])
            r_6.append(list(date_concat_s['日期'])[n])

    n += 1
s = {'日期': r_6, '商家编码': r_1, '商品数量': r_3, '平台': r_4, '平台1': r_5}
res_d = pd.DataFrame(s)
# print(result)
# res.to_excel(r'G:\结果\分列4.xlsx')

# 处理土豆粉出单

result_hz = res_d.groupby([res_d['平台1'], res_d['平台'], res_d['日期'], res_d['商家编码']], as_index=False).sum()
result_tdf = result_hz.copy()
# result_hz.reset_index(drop=False)


res_pp = pd.merge(result_hz, pp, on=['商家编码'], how='left')

# print(res_pp)

# 组合装处理
res_zh = pd.merge(result_1, pp_zh, on=['商家编码'], how='left')
res_zh.dropna(subset=['产品'], inplace=True)

result_re = pd.concat([res_pp, res_zh], axis=0)


# 提取商品袋数
def d(x):
    if '袋' in x:
        return re.findall(r"(\d+)袋", x)[-1]
    elif '桶' in x:
        return re.findall(r"(\d+)桶", x)[-1]
    elif ('个' in x):
        try:
            return re.findall(r"(\d+)个", x)[-1]
        except:
            return 1

    elif '包' in x:
        return re.findall(r"(\d+)包", x)[-1]
    elif ('只' in x):
        return re.findall(r"(\d+)只", x)[-1]
    elif ('根' in x):
        return re.findall(r"(\d+)根", x)[-1]
    else:
        return 0


# 处理总
result_re_zong = result_re.loc[result_re['单位'] == '总', :].copy()
result_re_zong['件数'] = 1
# 处理分
result_re_fen = result_re.loc[result_re['单位'] != '总', :].copy()
result_re_fen['件数'] = result_re_fen['商家编码'].map(d)

result_re_fen['件数'] = result_re_fen['件数'].astype(int)
# 处理未匹配上的
# result_re_na=result_re.loc[result_re['单位'].isnull(),:].copy()
# result_re_na['件数']='手动处理'

# print(result_re)

result_res = pd.concat([result_re_zong, result_re_fen], axis=0)

# result_res.to_excel(r'G:\结果\产品订单量结果_新10月.xlsx')
result_res['总件数'] = result_res['商品数量'] * result_res['件数']

result_res.to_excel(r'G:\工作\2025年订单\10月\结果\产品订单量结果_10月_1.xlsx')


# 判定产品类别

def f(x):
    if '+' in x or ('80g*土豆粉' in x) or ('80g小土豆粉' in x):
        return '其他'
    elif '173g大大桶' in x or ('大大桶' in x):
        return '173g大大桶麻酱米线'
    elif '140g火鸡面' in x or ('火鸡面' in x):
        return '140g火鸡面'
    elif '微麻微辣窝子面' in x or ('窝子面微麻微辣' in x):
        return '微麻微辣窝子面'
    elif '很麻很辣窝子面' in x:
        return '很麻很辣窝子面'
    elif '436g' in x or ('螺蛳粉' in x) or ('436螺蛳' in x):
        return '436g螺蛳粉土豆粉版'

    elif '粉面两掺' in x:
        return '粉面两掺'
    elif '133g袋装麻辣板面' in x or ('麻辣133g' in x):
        return '袋装麻辣板面'
    elif '133g袋装卤香板面' in x or ('卤香133g' in x) or ('卤香板面133g' in x):
        return '袋装卤香板面'
    elif '卤香板面桶装' in x or ('202g卤香板面' in x) or ('卤香板面202g' in x):
        return '桶装卤香板面'
    elif '146g麻辣板面' in x or ('麻辣牛肉板面146g' in x):
        return '146g桶装麻辣板面'
    elif '板面' in x:
        return '146g桶装卤香板面'

    elif '乐享杯' in x:
        return '乐享杯桶装'

    elif '乐享版家庭' in x:
        return '乐享家庭版麻酱米线'
    elif '线下家庭版' in x:
        return '线下家庭版麻酱米线'
    elif '家庭版袋装米线' in x or '家庭版' in x or '家庭麻酱米线' in x or '乐享版家庭' in x:
        return '家庭版麻酱米线'

    elif '欢享土豆粉' in x or '欢享版土豆粉' in x or '欢享版土豆' in x:
        return '欢享土豆粉'
    elif '轻享版' in x:
        return '轻享土豆粉'
    elif ('乐享版刀削面' in x) or ('乐享刀削面' in x):
        return '乐享刀削面'
    elif ('乐享版土豆粉' in x) or ('乐享土豆粉' in x) or ('286g' in x):
        return '乐享土豆粉'
    elif '荆芥土豆粉' in x:
        return '荆芥土豆粉'
    elif '荆芥麻酱米线' in x or ('荆芥袋装米线' in x):
        return '荆芥米线'
    elif ('肥汁米线桶装' in x) or ('肥汁桶装' in x):
        return '肥汁桶装'
    elif ('麻辣米线' in x):
        return '115g麻辣米线'

    elif '117g肥汁' in x or ('肥汁米线117g' in x):
        return '117g肥汁米线'
    elif '203g肥汁' in x or ('肥汁米线203g' in x):
        return '203g肥汁米线'
    elif '线下肥汁' in x:
        return '线下肥汁米线'
    elif '80g土豆粉' in x or ('土豆粉80g' in x) or ('80g*土豆粉' in x):
        return '其他'
    elif '板面底料1桶' in x or ('板面调料' in x):
        return '其他'
    elif x == '青春龙年礼盒':
        return '经典土豆粉'
    elif ('土豆粉') in x or ('士豆粉' in x):
        return '经典土豆粉'
    elif '豆芽板面' in x or ('166g' in x):
        return '豆芽板面'
    elif '板面' in x or ('146g' in x):
        return '桶装板面'
    elif '桶' in x:
        return '石磨桶装'
    elif ('青春' in x):
        return '青春袋装'

    elif ('传统' in x) or ('220g' in x):
        return '传统袋装'

    elif ('石磨' in x) or ('经典' in x) or ('麻酱' in x) or ('243g' in x) or ('来点尝一尝' in x) or ('01款' in x) or (
            '联名' in x):
        return '石磨袋装'
    elif '刀削面面饼' in x:
        return '其他'
    elif '刀削面' in x:
        return '刀削面'
    elif '烩面' in x:
        return '炝锅烩面'
    else:
        return '其他'


result_tdf['分类'] = result_tdf['商家编码'].map(f)


# 提取件数
def m(x):
    if x == '土豆粉龙年礼盒' or x == '青春龙年礼盒':
        return 6
    elif x == '刀削面龙年礼盒':
        return 3
    elif '烩面龙年礼盒' in x:
        return 6

    elif ('乐享版' in x) or ('轻享版' in x):
        try:
            return re.findall(r"(\d+)袋", x)[-1]
        except:
            return 0
    elif '土豆粉' in x or ('士豆粉' in x) or ('粉面两掺' in x):
        try:
            return re.findall(r"(\d+)袋", x)[-1]
        except:
            return 0
    elif '桶' in x:
        try:
            return re.findall(r"(\d+)桶", x)[-1]
        except:
            return 0
    elif ('石磨' in x) or ('经典' in x) or ('麻酱' in x) or ('传统' in x) or ('青春' in x) or ('麻辣' in x) or (
            '来点尝一尝' in x) or ('联名' in x) or ('荆芥' in x) or ('袋装米线' in x) or ('肥汁' in x):

        try:
            return re.findall(r"(\d+)袋", x)[-1]
        except:
            return 0
    elif '01款' in x:
        return 1
    elif ('刀削面' in x) or ('烩面' in x) or ('板面' in x):
        try:
            return re.findall(r"(\d+)袋", x)[-1]
        except:
            return 0
    else:
        return 0


result_tdf['件数'] = result_tdf['商家编码'].map(m)
result_tdf['件数'] = result_tdf['件数'].astype(int)
result_tdf['总件数'] = result_tdf['件数'] * result_tdf['商品数量']
# result_tdf.to_excel(r'G:\结果\土豆粉出单达人_新12月总.xlsx')

result_ = result_tdf.groupby(
    [result_tdf['平台'], result_tdf['平台1'], result_tdf['日期'], result_tdf['商家编码'], result_tdf['分类']],
    as_index=False).agg(总件数=('总件数', 'sum'))
result_.to_excel(r'G:\工作\2025年订单\10月\结果\土豆粉出单线上汇总10月总.xlsx')

sql11 = """ \
        SELECT Product_BianMa, Product_num, daren \
        from doudian_day \
        WHERE month (day)=10 \
          and Product_price \
            >0 \
          and (order_zt="完成" \
           OR order_zt="等待出库" \
           OR order_zt="等待确认收货" \
           OR order_zt="已签收" \
           OR order_zt="带配货" \
           OR order_zt="待发货" \
           OR order_zt="交易成功" \
           OR order_zt="已完成" \
           OR order_zt="卖家已发货，等待买家确认" \
           OR order_zt="买家已付款，等待卖家发货" \
           OR order_zt="已发货" \
           OR order_zt="调度中" \
           OR order_zt="已收货" \
           OR order_zt="已发货未签收" \
           OR order_zt="已发货，待签收" ) \
          and qudao='招商' \
          AND order_sh != "退款成功" \
          AND order_sh != "售后完成" \
          AND order_sh != "已全额退款" \
      """

cursor.execute(sql11)
result = cursor.fetchall()
dou = pd.DataFrame(list(result))

dou.columns = ['商家编码', '商品数量', '达人昵称']
# date_concat=dou[(dou['达人昵称'] != '宛禾米线官方旗舰店') &(dou['达人昵称'] != '宛禾米线速食官方旗舰店')&(dou['达人昵称'] != '宛禾食品旗舰店') &(dou['达人昵称'] != '宛禾食品旗舰店直播间')&(dou['达人昵称'] != '宛禾米线') &(dou['达人昵称'] != '宛禾速食官方旗舰店')&(dou['达人昵称'] != '宛禾速食旗舰店')
# &(dou['达人昵称'] != '宛禾食品')&(dou['达人昵称'] != '宛禾速食直播间')&(dou['达人昵称'] != '宛禾食品旗舰店甄选号')&(dou['达人昵称'] != '宛禾牛宅')&(dou['达人昵称'] != '宛禾食品旗舰店自播间') &(dou['达人昵称'] != '宛禾官方旗舰店')]
date_concat = dou
date_concatd = date_concat.groupby([date_concat['达人昵称'], date_concat['商家编码']], as_index=False).agg(
    商品单量=('商品数量', 'count'))
# 单量
xs = date_concatd

pp = pd.read_excel(r'G:\工作\商家编码匹配产品.xlsx')  # 匹配表

# 所有产品，包含组合装
# 处理每行多订单情况
# 分列
s_1 = []  # 分列后以列表形式保存
r_1 = []  # 添加每个分列后的产品
r_3 = []  # 添加商品数量
r_4 = []  # 添加平台
r_5 = []  # 添加SKU
for date_s in list(xs['商家编码']):
    if '+' in date_s:
        date_split = str(date_s).split('+')
        s_1.append(date_split[0])
    elif '，' in date_s:
        date_split = str(date_s).split('，')
        if '赠' in date_split[0]:
            date_split_1 = date_split[0].split('赠')
            s_1.append(date_split_1[0])
        else:
            s_1.append(date_split[0])


    elif '赠' in date_s:

        date_split = str(date_s).split('赠')
        s_1.append(date_split[0])


    elif '＋' in date_s:
        date_split = str(date_s).split('＋')
        s_1.append(date_split[0])
    else:
        s_1.append(date_s)

xs['主产品'] = s_1

xs = xs.reset_index(drop=True)

xs = xs.loc[:, ['达人昵称', '主产品', '商品单量']]
result_hz = xs.groupby([xs['达人昵称'], xs['主产品']], as_index=False).sum()

# 判定产品类别
def f(x):
    if '+' in x :
        return '其他'
    elif '乐享杯' in x :
        return '乐享杯桶装'
    elif '家庭版袋装米线' in x or '家庭版' in x:
        return '家庭版麻酱米线'
    elif '欢享土豆粉' in x or '欢享版土豆粉' in x  :
        return '欢享土豆粉'
    elif '轻享版' in x :
        return '轻享土豆粉'
    elif '乐享版刀削面' in x :
        return '乐享刀削面'
    elif '乐享版' in x :
        return '乐享土豆粉'
    elif '荆芥土豆粉' in x :
        return '荆芥土豆粉'
    elif '荆芥麻酱米线' in x  or  ('荆芥袋装米线' in x) :
        return '荆芥米线'
    elif '肥汁' in x  :
        return '肥汁米线'
    elif '80g土豆粉' in x or  ('土豆粉80g' in x):
        return '其他'
    elif '板面底料1桶' in x :
        return '其他'
    elif x=='青春龙年礼盒' :
        return '经典土豆粉'
    elif ('土豆粉') in x or  ('士豆粉' in x) :
        return '经典土豆粉'
    elif '豆芽板面' in x or ('166g' in x ):
        return '豆芽板面'
    elif '板面' in x or ('146g' in x ):
        return '桶装板面'
    elif '桶' in x :
        return '桶装米线'
    elif ('石磨' in x ) or ('经典' in x ) or ('麻酱' in x ) or ('传统' in x ) or ('青春' in x ) or ('麻辣' in x ) or ('来点尝一尝' in x ) or ('01款' in x )or ('联名' in x ):
        return  '袋装米线'
    elif '刀削面面饼' in x :
        return '其他'
    elif '刀削面' in x :
        return '刀削面'
    elif '烩面' in x :
        return '炝锅烩面'
    else :
        return '其他'

#提取件数
def m(x):
    if x=='土豆粉龙年礼盒' or   x=='青春龙年礼盒':
        return 6
    elif  x=='刀削面龙年礼盒' :
        return 3
    elif  '烩面龙年礼盒' in x :
        return 6

    elif ('乐享版' in x ) or  ('轻享版' in x ) :
        try:
            return re.findall(r"(\d+)袋",x)[-1]
        except :
            return 0
    elif '土豆粉' in x  or  ('士豆粉' in x):
        try:
            return re.findall(r"(\d+)袋",x)[-1]
        except :
            return 2
    elif '桶' in x :
        try:
            return re.findall(r"(\d+)桶",x)[-1]
        except :
            return 0
    elif ('石磨' in x ) or ('经典' in x ) or ('麻酱' in x ) or ('传统' in x ) or ('青春' in x ) or ('麻辣' in x ) or ('来点尝一尝' in x ) or ('联名' in x ) or ('荆芥' in x )or ('袋装米线' in x ) or ('肥汁' in x ):

        try:
            return  re.findall(r"(\d+)袋",x)[-1]
        except :
            return 1
    elif '01款' in x :
        return 1
    elif ('刀削面' in x)  or  ('烩面' in x ):
        try:
            return re.findall(r"(\d+)袋",x)[-1]
        except :
            return 2
    else :
        return 0


result_hz['分类'] = result_hz['主产品'].map(f)
result_hz['件数'] = result_hz['主产品'].map(m)
result_hz['件数'] = result_hz['件数'].astype(int)
# result_hz['总件数']=result_hz['件数'] * result_hz['商品数量']
result_hz.to_excel(r'G:\工作\2025年订单\10月\结果\土豆粉出单达人10月.xlsx')
